from django.shortcuts import render
from jsonrpc import jsonrpc_method
from api.models import VN
from django.db.models import Count

@jsonrpc_method('api.pie_chart')
def pie_chart(request):
    l = []
    cuentas = VN.objects.all().values('uai').annotate(count=Count('uai')).order_by('-count')
    n = VN.objects.all().count()
    for i in cuentas:
        print i
        l.append([i["uai"],int(i["count"])/float(n)*100])
    return l

@jsonrpc_method('api.get_uais')
def get_uai(request):
    cuentas = VN.objects.all().values('uai').distinct()
    l = []
    for i in cuentas:
        l.append(i["uai"])
    return l
